package com.ming.reggie.mapper;

import com.ming.reggie.dto.DishDto;
import com.ming.reggie.entity.Dish;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface DishMapper {

    @Select("select count(0) from dish where category_id = #{cid} and is_deleted = 0")
    Integer findByCid(Long cid);

    @Insert("insert into dish values (null,#{name},#{categoryId},#{price},#{code},#{image},#{description},#{status},#{sort},#{createTime},#{updateTime},#{createUser},#{updateUser},0)")
    @Options( useGeneratedKeys = true,keyColumn = "id",keyProperty = "id")
    Integer addDish(DishDto dishDto);


    @Select("select * from dish where category_id = #{categoryId} and is_deleted = 0 and status = 1 order by sort asc ")
    List<Dish> findByCategoryId(Long categoryId);

    //根据类别id和状态查询菜品列表
    @Select("select * from dish where category_id = #{categoryId} and status = #{status} and is_deleted=0 order by sort asc" )
    List<Dish> findByCategoryIdAndStatus(@Param("categoryId") Long categoryId,
                                         @Param("status") Integer status);
}
